library(ggplot2)
library(readr)
chic <- read_csv("ggplot2/ggModify/chicago-nmmaps.csv")

# 曲线下区域AUC, 置信区域CI等
# 在这个例子中，我们将使用filter()函数创建一个30天的平均运行时间，这样我们的ribbon就不会有太多噪音。

chic$o3run <- as.numeric(stats::filter(chic$o3, rep(1/30, 30), sides = 2))

ggplot(chic, aes(x = date, y = o3run)) +
   geom_line(color = "chocolate", lwd = .8) +
   labs(x = "Year", y = "Ozone")

# 如果我们使用geom_ribbon()函数填充曲线下面的区域会是什么样子?

ggplot(chic, aes(x = date, y = o3run)) +
   geom_ribbon(aes(ymin = 0, ymax = o3run),
               fill = "orange", alpha = .4) +
   geom_line(color = "chocolate", lwd = .8) +
   labs(x = "Year", y = "Ozone")

# 另外，我们还可以画一条带，在数据上下分别给出一个标准差:
chic$mino3 <- chic$o3run - sd(chic$o3run, na.rm = TRUE)
chic$maxo3 <- chic$o3run + sd(chic$o3run, na.rm = TRUE)

ggplot(chic, aes(x = date, y = o3run)) +
   geom_ribbon(aes(ymin = mino3, ymax = maxo3), alpha = .5,
               fill = "darkseagreen3", color = "transparent") +
   geom_line(color = "aquamarine4", lwd = .7) +
   labs(x = "Year", y = "Ozone")
   